import React, {Component} from 'react'
import {
    View,
    Text,
    Image,
    StyleSheet,
    ListView
} from 'react-native'

var Dimensions = require('Dimensions')
var {width} = Dimensions.get('window')

export default class CommonListItem extends Component {

    constructor(props) {
        super(props)
        var ds = new ListView.DataSource({rowHasChanged: (row1, row2) => row1 !== row2});
        this.state = {
            dataSource: ds.cloneWithRows(this.props.itemData)
        }
        console.log('我操')
    }

    render() {
        {/*<ListView*/}
        {/*contentContainerStyle={styles.listContent}*/}
        {/*dataSource={this.state.dataSource}*/}
        {/*// renderRow={this.renderItem = this.renderItem().bind(this)}*/}
        {/*renderRow={(data) => <Text style={styles.itemContainer}>data.title</Text>}*/}
        {/*enableEmptySections={true}*/}
        {/*scrollEnable={false}*/}
        {/*/>*/}

        return (
            <View style={styles.itemContainer}>
                <View style={styles.leftTextContainer}>
                    <Text style={[styles.titleStyle, {color: this.props.titleColor}]}>{this.props.title}</Text>
                    <Text style={styles.subTitleStyle}>{this.props.title}</Text>
                </View>
                <Image
                    style={styles.rightImage}
                    source={{uri: 'http://localhost:8081/imgs/hot_eat.png'}}/>
            </View>
        )
    }

    renderItem(item) {
        console.log(item)
        return (
            <View style={styles.itemContainer}>
                <View style={styles.leftTextContainer}>
                    {/*<Text style={[styles.titleStyle, {color: item.titleColor}]}>{item.title}</Text>*/}
                    <Text style={styles.subTitleStyle}>{item.maintitle}</Text>
                </View>
                <Image
                    style={styles.rightImage}
                    source={{uri: 'http://localhost:8081/imgs/hot_eat.png'}}/>
            </View>
        )
    }
}

const styles = StyleSheet.create({
    titleStyle: {
        fontSize: 18,
    },
    subTitleStyle: {
        fontSize: 14
    },
    rightImage: {
        height: 35,
        width: 55
    },
    leftTextContainer: {
        justifyContent: 'center'
    },

    listContent: {
        width: (width - 1) / 2,
        flexDirection: 'row',
        flexWrap: 'wrap',
    },

    itemContainer: {
        width: (width - 1) / 2,
        height: 70,
        alignItems: 'center',
        justifyContent: 'space-between',
        backgroundColor: 'white'
    },
})